package cn.lingyangwl.agile.msg.push.controller;

import cn.lingyangwl.agile.infra.InfraApi;
import cn.lingyangwl.agile.infra.module.group.model.rqrs.DataGroupSaveReq;
import cn.lingyangwl.agile.infra.module.group.model.rqrs.DataGroupUpdateReq;
import cn.lingyangwl.agile.model.enums.DataGroupBizTypeEnum;
import cn.lingyangwl.agile.msg.push.service.*;
import cn.lingyangwl.agile.ram.ActionType;
import cn.lingyangwl.agile.ram.RamResource;
import cn.lingyangwl.framework.core.response.Resp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * 消息功能组
 *
 * @author shenguangyang
 */
@Api(tags = "消息功能组")
@RestController
@RequestMapping("/msgGroup")
public class MsgGroupController {
    @Resource
    private MsgNoticeService noticeService;

    @Resource
    private InfraApi infraApi;

    @ApiOperation(value = "保存消息功能组")
    @PostMapping("/save")
    @RamResource(action = "msg:msgGroup:save", name = "保存消息功能组", type = ActionType.WRITE)
    public Resp<?> saveDataGroup(@RequestBody DataGroupSaveReq req) {
        req.setBizType(DataGroupBizTypeEnum.MSG_PUSH_TASK.getType());
        return Resp.ok(infraApi.saveDataGroup(req));
    }

    @ApiOperation(value = "更新消息功能组")
    @PostMapping("/update")
    @RamResource(action = "msg:msgGroup:update", name = "更新消息功能组", type = ActionType.WRITE)
    public Resp<?> updateDataGroup(@RequestBody DataGroupUpdateReq req) {
        return Resp.ok(infraApi.updateDataGroup(req));
    }

    @ApiOperation(value = "批量删除消息功能组")
    @DeleteMapping("/batchDelete")
    @RamResource(action = "msg:msgGroup:delete", name = "删除消息功能组", type = ActionType.WRITE)
    public Resp<?> batchDeleteDataGroup(@RequestParam(value = "ids") List<Long> ids) {
        return Resp.ok(noticeService.batchDeleteGroup(ids));

    }

    @ApiOperation(value = "删除消息功能组")
    @DeleteMapping("/delete")
    @RamResource(action = "msg:msgGroup:delete", name = "删除消息功能组", type = ActionType.WRITE)
    public Resp<?> deleteDataGroup(@RequestParam(value = "id") Long id) {
        return Resp.ok(noticeService.batchDeleteGroup(Collections.singletonList(id)));
    }
}
